﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:DaxStudio.UI.Experiments">


    <!--<SolidColorBrush x:Key="SpinnerColorBrush" Color="Black"></SolidColorBrush>-->
    <local:OffsetConverter x:Key="OffsetConverter"/>
    
    <Storyboard x:Key="Rotation">
        <DoubleAnimation Storyboard.TargetName="rotateTransform"
                       Storyboard.TargetProperty="Angle"
                       From="0" To="360" Duration="00:00:01"
                       RepeatBehavior="Forever"/>
    </Storyboard>

    <Style x:Key="SpinnerStyle" TargetType="Label">
        <Style.Setters>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Grid Name="LayoutRoot" RenderTransformOrigin="0.5,0.5" Background="{TemplateBinding Background}">
                            <Grid.RenderTransform>
                                <TransformGroup>
                                    <RotateTransform x:Name="rotateTransform"/>
                                </TransformGroup>
                            </Grid.RenderTransform>
                            <Ellipse Fill="{TemplateBinding Foreground }">
                               

                                <Ellipse.OpacityMask>
                                    <ImageBrush ImageSource="SpinnerMask.png" Stretch="None"/>
                                </Ellipse.OpacityMask>
                            </Ellipse>
                            <Grid.OpacityMask>
                                <RadialGradientBrush>
                                    <GradientStop Color="Black" Offset="0.96"/>
                                    <GradientStop Color="Transparent" Offset="0.6"/>
                                </RadialGradientBrush>
                            </Grid.OpacityMask>
                            <Grid.Triggers>
                                <EventTrigger RoutedEvent="Window.Loaded">
                                    <BeginStoryboard>
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="rotateTransform"
                                            Storyboard.TargetProperty="Angle"
                                            From="0" To="360" Duration="00:00:01"
                                            RepeatBehavior="Forever"/>
                                        </Storyboard>
                                    </BeginStoryboard>
                                </EventTrigger>
                            </Grid.Triggers>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style.Setters>
    </Style>


    <Style x:Key="LabelSpinnerStyle" TargetType="{x:Type Label}">
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Padding" Value="0"/>
        <!--<Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Top"/>-->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Label}">
                        
                    <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
                        <StackPanel Orientation="Horizontal">
                            <Grid Name="LayoutRoot" RenderTransformOrigin="0.5,0.5" 
                                  Width="{TemplateBinding Height,Converter={StaticResource OffsetConverter},ConverterParameter=3}"
                                  Height="{TemplateBinding Height,Converter={StaticResource OffsetConverter},ConverterParameter=3}"
                                  Background="{TemplateBinding Background}">
                                
                                <Grid.RenderTransform>
                                    <TransformGroup>
                                        <RotateTransform x:Name="rotateTransform"/>
                                    </TransformGroup>
                                </Grid.RenderTransform>
                                <Ellipse Margin="2" Fill="{TemplateBinding Foreground }">


                                    <Ellipse.OpacityMask>
                                        <ImageBrush ImageSource="SpinnerMask.png" Stretch="None"/>
                                    </Ellipse.OpacityMask>
                                </Ellipse>
                                <Grid.OpacityMask>
                                    <RadialGradientBrush>
                                        <GradientStop Color="Black" Offset="0.96"/>
                                        <GradientStop Color="Transparent" Offset="0.5"/>
                                    </RadialGradientBrush>
                                </Grid.OpacityMask>
                                <Grid.Triggers>
                                    <EventTrigger RoutedEvent="Window.Loaded">
                                        <BeginStoryboard>
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetName="rotateTransform"
                                            Storyboard.TargetProperty="Angle"
                                            From="0" To="360" Duration="00:00:01"
                                            RepeatBehavior="Forever"/>
                                            </Storyboard>
                                        </BeginStoryboard>
                                    </EventTrigger>
                                </Grid.Triggers>
                            </Grid>
                            <ContentPresenter Margin="5,0,0,0" 
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                              RecognizesAccessKey="True" 
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                        </StackPanel>
                        </Border>
                    
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    <Style x:Key="TextSpinnerStyle" TargetType="Label">
        <Style.Setters>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <StackPanel Orientation="Vertical">
                            <Grid Name="LayoutRoot" RenderTransformOrigin="0.5,0.5" Background="{TemplateBinding Background}">
                                <Grid.RenderTransform>
                                    <TransformGroup>
                                        <RotateTransform x:Name="rotateTransform"/>
                                    </TransformGroup>
                                </Grid.RenderTransform>
                                <Ellipse Fill="{TemplateBinding Foreground }">
                                    <!--<Ellipse Fill="{DynamicResource SpinnerColorBrush}">-->

                                    <Ellipse.OpacityMask>
                                        <ImageBrush ImageSource="SpinnerMask.png" Stretch="None"/>
                                    </Ellipse.OpacityMask>
                                </Ellipse>
                                <Grid.OpacityMask>
                                    <RadialGradientBrush>
                                        <GradientStop Color="Black" Offset="0.96"/>
                                        <GradientStop Color="Transparent" Offset="0.6"/>
                                    </RadialGradientBrush>
                                </Grid.OpacityMask>
                                <Grid.Triggers>
                                    <EventTrigger RoutedEvent="Window.Loaded">
                                        <BeginStoryboard>
                                            <Storyboard>
                                                <DoubleAnimation Storyboard.TargetName="rotateTransform"
                                                Storyboard.TargetProperty="Angle"
                                                From="0" To="360" Duration="00:00:01"
                                                RepeatBehavior="Forever"/>
                                            </Storyboard>
                                        </BeginStoryboard>
                                    </EventTrigger>
                                </Grid.Triggers>
                            </Grid>
                            <TextBlock Foreground="{TemplateBinding Foreground}" Text="{TemplateBinding Label.Content}"></TextBlock>
                        </StackPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style.Setters>
    </Style>

</ResourceDictionary>